package com.zyy.state.demo02;

/**
 * @Description: 类描述
 * @Author: zyy
 * @Date: 2023/08/08 23:18
 */
public class Context {
    //定义出所有的电梯状态
    //开门状态 电梯可以关门
    public final static OpeningState OPENING_STATE = new OpeningState();
    //关门状态 电梯可以运行，停止，开门
    public final static ClosingState CLOSING_STATE = new ClosingState();
    //运行状态 电梯可以停止
    public final static RunningState RUNNING_STATE = new RunningState();
    //停止状态 电梯可以开门，运行
    public final static StoppingState STOPPING_STATE = new StoppingState();

    private LiftState liftState;

    public LiftState getLiftState() {
        return this.liftState;
    }

    public void setLiftState(LiftState liftState) {
        //当前环境改变
        this.liftState = liftState;
        //把当前的环境通知到各个实现类中
        this.liftState.setContext(this);
    }


    //电梯开门动作
    public void open() {
        this.liftState.open();
    }


    //电梯关门动作
    public void close() {
        this.liftState.close();
    }


    //电梯运行动作
    public void run() {
        this.liftState.run();
    }


    //电梯停止动作
    public void stop() {
        this.liftState.stop();
    }
}
